#!/bin/bash
file_name=functions.sh
funcs=`which $file_name`
if [ "$funcs" != "" ] ;then
  echo "funcs=$funcs"
  . $funcs
else
  funcs=`dirname $0`/$file_name
  echo "$PWD"
  echo "funcs=$funcs"
  if [ "$funcs" != "" ] ;then
    . $funcs
  else
    exit
  fi
fi
#编译 android 4.0 版本
start_time=003000
end_time=063000
cur_time=`sh_get_time2`
echo "cur_time=$cur_time"
platform=$1
project=$2

if [ "$platform" = "MT6575" ]; then
  l_platform=$platform
  l_product_name=bbk75_cu_ics
  l_project_name=$project
  l_hardware_suffix=MA
  l_options="--with-app-repo" # --no-update
  l_svn_version="-R 3400 -r head"
  l_work_copy=ALPS.ICS.MP.V2_W_20120504_test
  l_app_url=http://smartphone/repositories/AppsOfMtk/trunk/packages-w1140/
elif [ "$platform" = "MT6515" ]; then
  l_platform=$platform
  l_product_name=bbk15_td_ics
  l_project_name=$project
  l_hardware_suffix=MA
  l_options="--with-app-repo"
  l_svn_version="-R 2900 -r head"
  l_work_copy=ALPS.ICS.MP.V2.2_TD_20120521test
  l_app_url=http://smartphone/repositories/AppsOfMtk/trunk/packages-w1140/
elif [ "$platform" = "MT6577" ]; then
  l_platform=$platform
  l_product_name=bbk77_cu_ics2
  l_project_name=PD1211W
  l_temp_app_project_name=PD1208
  l_hardware_suffix=MA
  #l_options="--with-app-repo"
  l_svn_version="-R 657 -r head"
  l_work_copy=ALPS.ICS2.MP.V1_W_20120703_test
  l_app_url=http://smartphone/repositories/AppsOfMtk/trunk/packages-w1140/
elif [ "$platform" = "MSM8225" ]; then
  l_platform=$platform
  l_product_name=bbk77_cu_ics2
  l_project_name=$project
  l_hardware_suffix=MA
  l_options="--with-app-repo"
  l_svn_version="-R 2900 -r head"
  l_work_copy=ALPS.ICS2.6577.SP.V1_20120607_test
  l_app_url=http://smartphone/repositories/AppsOfMtk/trunk/packages-w1140/
else
  echo "推出！！"
  exit
fi

#一些初始化参数
b_update=true
l_bbk_version="-v `sh_get_date_and_time2 "date"`"
l_work_copy=~/workspace/gphone/$l_platform/${l_project_name}/${l_work_copy}
l_hardware=${l_project_name}${l_hardware_suffix}
#
if [ $cur_time -gt $start_time -a $cur_time -lt $end_time ]; then
  echoTextBlue "全新编译......"
  l_mode=auto
  l_build=new
  l_svn_version=
else
  echoTextBlue "增量编译......"
  l_mode=test
  if test -f $l_work_copy/.automake-test.ini; then
     ac_version=`parseini.shc $l_work_copy/.automake-test.ini get versions_info framework`
     echo "ac_version=$ac_version"
     if [ -n "$ac_version" ]; then
       l_svn_version="-R $ac_version"
     fi
  fi
  l_build=remake
fi
#处理额外参数
if [ "$b_update" != "true" ]; then
l_options="$l_options --no-update"
fi
if [ -n "$l_svn_version" ]; then
l_options="$l_options $l_svn_version"
fi
if [ -n "$l_bbk_version" ]; then
l_options="$l_options $l_bbk_version"
#bbk_version=`echo $l_bbk_version | sed "s/-v//g"`
fi
#############################
#自动编译
echo "automake.sh --work-copy $l_work_copy --app-url $l_app_url -d  $l_product_name  -p $l_project_name --temp-app $l_temp_app_project_name -h $l_hardware -b $l_build -m $l_mode  $l_options"
automake.sh --work-copy $l_work_copy --app-url $l_app_url -d  $l_product_name  -p $l_project_name --temp-app $l_temp_app_project_name -h $l_hardware -b $l_build -m $l_mode  $l_options
if test -d $l_work_copy; then
  #sh_auto_version_mtk $l_work_copy $l_product_name $bbk_version
  autopack.sh --work-copy $l_work_copy -d $l_product_name -p $l_project_name --no-tar --no-upload
fi

if [ "$l_mode" = "test" ] && test -d $l_work_copy; then
  echo "fetion.sh --work-copy $l_work_copy -d  $l_product_name -m compiler"
  fetion.sh --work-copy $l_work_copy -d  $l_product_name -m compiler
fi
if [ "$l_mode" = "auto" ] && test -d $l_work_copy; then
  echo "fetion.sh --work-copy $l_work_copy -d  $l_product_name -m compiler"
  fetion.sh --work-copy $l_work_copy -d  $l_product_name -m compiler
fi
#删除多余的包
l_release_dir=~/workspace/gphone/release/$l_project_name/images
if test -d $l_release_dir; then
  end_date=`sh_get_date_and_time2 "date"`
  echo "cur_date=$end_date"
  ((start_date=end_date-7))
  ((end_date=end_date-2))
  for i in `seq $start_date $end_date`
  do
    if [ -z "$ac_grep" ]; then
      ac_grep="$i"
    else
      ac_grep="$i|$ac_grep"
    fi
  done 
  echo "ac_grep=$ac_grep"
 # echo "find  $l_release_dir  -path '*/.*'   -prune -o  -type d | sort |uniq  | grep -E $ac_grep"
  find  $l_release_dir  -path '*/.*'   -prune -o  -type d | sort |uniq |grep -E $ac_grep |xargs rm -rf
fi
exit

%admin ALL=(ALL) NOPASSWD: NOPASSWD
%admin ALL=(ALL) ALL


# Allow members of iqoouser to execute commands listed below, by suludi 2011-3-8
# Members of the iqoouser group may gain root privileges
%iqoouser ALL=(root) /bin/mount, /bin/umount, /sbin/mount.cifs


User_Alias ABC = abc
Cmnd_Alias DEFAULT=/sbin/ldconfig,/bin/mount,sudoedit /etc/exports,/usr/bin/passwd
ABC ALL=(ALL)NOPASSWD:DEFAULT



